<template>
  <div class="warehousearea">
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
    </avue-crud>
  </basic-container>
  </div>
</template>

<script>
  import {getList, getDetail} from "@/api/jypx/eduwlofflinetrainingrecord/WlfOnlinetrainingrecords";
  import {mapGetters} from "vuex";

  export default {
    data() {
      return {
        studyRecords:{},
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
          height:'auto',
          calcHeight: 30,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          selection: true,
          dialogClickModal: false,
          column: [
            {
              label: "姓名",
              prop: "ksrName",
              search: true,
              align: "center",
              rules: [{
                required: true,
                message: "请输入",
                trigger: "blur"
              }]
            },
            {
              label: "身份证号",
              prop: "ksrCard",
              align: "center",
              rules: [{
                required: true,
                message: "请输入",
                trigger: "blur"
              }]
            },
            {
              label: "培训类别",
              prop: "wlpxlb",
              row: false,
              align: "center",
              width:"130px",
              type:"select",
              dataType: "number",
              dicUrl:"/api/blade-system/dict-biz/dictionary?code=wlofflinetrainingrecord_pxlb",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "请输入",
                trigger: "blur"
              }]
            },
            {
              label: "外来方单位名称",
              prop: "deptName",
              align: "center",
              width:"130px",
              labelWidth:120,
              rules: [{
                required: true,
                message: "请输入",
                trigger: "blur"
              }]
            },
            // {
            //   label: "学习内容",
            //   prop: "kcmc",
            //   align: "center",
            //   width:"150px",
            //   rules: [{
            //     required: true,
            //     message: "请输入",
            //     trigger: "blur"
            //   }]
            // },
            // {
            //   label: "学习时间",
            //   prop: "startTime",
            //   align: "center",
            //   width:"150px",
            //   type: "datetime",
            //   format: "yyyy-MM-dd hh:mm:ss",
            //   valueFormat: "yyyy-MM-dd hh:mm:ss",
            //   rules: [{
            //     required: true,
            //     message: "请输入",
            //     trigger: "blur"
            //   }]
            // },
            {
              label: "考试时间",
              prop: "ksTime",
              row: false,
              align: "center",
              width:"150px",
              type: "datetime",
              format: "yyyy-MM-dd hh:mm:ss",
              valueFormat: "yyyy-MM-dd hh:mm:ss",
              rules: [{
                required: true,
                message: "请输入",
                trigger: "blur"
              }]
            },
            {
              label: "培训成绩",
              prop: "kscj",
              align: "center",
              rules: [{
                required: true,
                message: "请输入",
                trigger: "blur"
              }]
            },
            {
              label: "培训结果",
              prop: "ksjg",
              row: false,
              align: "center",
              type:"select",
              dataType: "number",
              dicUrl:"/api/blade-system/dict-biz/dictionary?code=ksjg",
              props: {
                label: "dictValue",
                value: "dictKey"
              },
              rules: [{
                required: true,
                message: "请输入",
                trigger: "blur"
              }]
            },
            {
              label: "租户id",
              prop: "tenantId",
              hide: true,
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false
            },
          ]
        },
        data: [],
      };
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: false,
          viewBtn: this.vaildData(this.permission.wlofflinetrainingrecord_view, false),
          delBtn: false,
          editBtn: false
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {

      // rowSave(row, done, loading) {
      //   add(row).then(() => {
      //     this.onLoad(this.page);
      //     this.$message({
      //       type: "success",
      //       message: "操作成功!"
      //     });
      //     done();
      //   }, error => {
      //     loading();
      //     window.console.log(error);
      //   });
      // },
      // rowUpdate(row, index, done, loading) {
      //   update(row).then(() => {
      //     this.onLoad(this.page);
      //     this.$message({
      //       type: "success",
      //       message: "操作成功!"
      //     });
      //     done();
      //   }, error => {
      //     loading();
      //     console.log(error);
      //   });
      // },
      // rowDel(row) {
      //   this.$confirm("确定将选择数据删除?", {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //     type: "warning"
      //   })
      //     .then(() => {
      //       return remove(row.id);
      //     })
      //     .then(() => {
      //       this.onLoad(this.page);
      //       this.$message({
      //         type: "success",
      //         message: "操作成功!"
      //       });
      //     });
      // },
      // handleDelete() {
      //   if (this.selectionList.length === 0) {
      //     this.$message.warning("请选择至少一条数据");
      //     return;
      //   }
      //   this.$confirm("确定将选择数据删除?", {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //     type: "warning"
      //   })
      //     .then(() => {
      //       return remove(this.ids);
      //     })
      //     .then(() => {
      //       this.onLoad(this.page);
      //       this.$message({
      //         type: "success",
      //         message: "操作成功!"
      //       });
      //       this.$refs.crud.toggleSelection();
      //     });
      // },
      beforeOpen(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetail(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1;
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      }
    }
  };
</script>

<style lang="scss" scpoed>
  .warehousearea {
  .el-form-item__label {
    width: 120px !important;
  }
  .avue-form__row {
  .el-form-item__content {
    margin-left: 120px !important;
  }
  }
  }
</style>
